package com.pdf;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 给文档设置密码
 * @author liyiruo
 * @Description
 * @Date 2021/8/10 下午4:16
 */
public class EncrypPDF {
    public static void main(String[] args) throws DocumentException, FileNotFoundException {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DemoPDF.path + "EncrypPDF.pdf"));
        // 设置密码为："World",用这个方法需要引入一个依赖˚
        writer.setEncryption("Hello".getBytes(), "World".getBytes(),
                PdfWriter.ALLOW_SCREENREADERS,
                PdfWriter.STANDARD_ENCRYPTION_128);

        document.open();
        document.add(new Paragraph("EncrypPDF"));
        document.close();
    }
}
